<?php


namespace App\Services;


use Hhxsv5\LaravelS\Swoole\WebSocketHandlerInterface;
use Illuminate\Support\Facades\Log;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
use Swoole\WebSocket\Server;

class WebSocketService implements WebSocketHandlerInterface
{
  public function __construct()
  {

  }

  public function onOpen(Server $server, Request $request)
  {
      Log::info("webSocket链接已建立");
      $server->push($request->fd,"LaravelS  websocket连接成功");
  }

  public function onMessage(Server $server, Frame $frame)
  {
     $server->push($frame->fd,"消息已收到".date("Y-m-d H:i:s"));
  }

  public function onClose(Server $server, $fd, $reactorId)
  {
      Log::info("webSocket链接关闭");
  }
}